<?php

//微信端
Route::group(['middleware' => ['simulate', 'oauth'], 'namespace' => 'Customer'], function(){
	//异步接口
	Route::group(['namespace' => 'Api', 'prefix' => 'api'], function(){
		//用户
		Route::group(['prefix' => 'user'], function(){
			Route::post('info', 'UserController@updateUserInfo');
		});

		//设备
		Route::group(['prefix' => 'device/{type}'], function(){
			//绑定
			Route::post('bind', 'DeviceController@bind');
			//水机控制
			Route::post('control', 'DeviceController@control');
			//解绑
			Route::post('unbind', 'DeviceController@unbind');
		});
	});

	//同步页面
	Route::group(['namespace' => 'Pages'], function(){

		//bind前填写信息
		Route::get('{type}/user/info', 'UserController@info');

		//微信端首页，选择型号
		Route::get('index', 'DeviceController@index');
		//设备
		Route::group(['prefix' => 'device/{type}', 'middleware' => 'deviceType'], function(){
			//配网页面
			Route::get('connect', 'DeviceController@connect');
			//绑定页面
			Route::get('bind', 'DeviceController@bind');
			//水机控制页面 state,
			Route::get('state', 'DeviceController@getState');
			//水机滤芯页面 filters
			Route::get('filters', 'DeviceController@getFilters');
			//设备信息
			Route::get('info', 'DeviceController@info');
			//解绑页面
			Route::get('unbind', 'DeviceController@unbind');

			//用户
			Route::group(['prefix' => 'user'], function(){
				//bind后填写信息
				Route::get('info', 'UserController@userInfo');
			});
		});
	});
});

//后台管理
Route::group(['middleware' => ['simulate', 'redirect', 'admin'], 'namespace' => 'Admin', 'prefix' => 'admin'], function(){
	//异步接口
	Route::group(['namespace' => 'Api', 'prefix' => 'api'], function(){
		//用户
		Route::group(['prefix' => 'user'], function(){
			//登录
			Route::post('login', 'UserController@login');
			//添加管理员
			Route::post('add', 'UserController@add');
			//更新管理员信息
			Route::post('update', 'UserController@update');
			//更新管理员密码
			Route::post('update-password', 'UserController@updatePassword');
			//删除管理员
			Route::post('delete', 'UserController@delete');
			//登出
			Route::post('logout', 'UserController@logout');
			//根据用户姓名获取用户信息
			Route::get('customer', 'UserController@customersFindByName');
		});
		//设备/类型
		Route::group(['prefix' => 'device/types'], function(){
			// 以下接口为方便后续添加设备类型所做扩展
			//获取全部设备类型
			Route::get('/', 'DeviceController@allType');
			//添加设备类型
			Route::post('add', 'DeviceController@addType');
			//更新设备类型
			Route::post('update', 'DeviceController@updateType');
			//删除设备类型
			Route::post('delete', 'DeviceController@deleteType');
		});
	});
	//同步页面
	Route::group(['namespace' => 'Pages'], function(){
		//用户
		Route::group(['prefix' => 'user'], function(){
			//登录页面
			Route::get('login', 'UserController@login');
			//用户信息页面
			Route::get('customers', 'UserController@customers');
			//账号管理
			Route::get('index', 'UserController@index');
		});
		//设备
		Route::group(['prefix' => 'device'], function(){
			//设备列表
			Route::get('index', 'DeviceController@index');
			//历史记录
			Route::get('history', 'DeviceController@history');
		});
	});
});

Route::group(['namespace' => 'Customer\Api'], function(){
	Route::get('wechat', 'WeChatController@config');
	Route::post('wechat', 'WeChatController@react');
	Route::get('menu', 'WeChatController@createMenu');
});